import {
  GetCategoryOneId,
  GetCategoryTwoUrl,
  GetCategoryThreeUrl
} from '@/api/product/category'
export default {
  state: {
    category1Id: undefined,
    category2Id: undefined,
    category3Id: undefined,
    categoryOneList: [],
    categoryTwoList: [],
    categoryThreeList: []
  },
  mutations: {
    UPDATE_ONELIST(state, CategoryOneList) {
      state.categoryOneList = CategoryOneList
    },
    UPDATE_TWOLIST(state, categoryTwoList) {
      state.categoryTwoList = categoryTwoList
    },
    UPDATE_ThreeLIST(state, categoryThreeList) {
      state.categoryThreeList = categoryThreeList
    }
  },
  actions: {
    async getCategoryOneList({ commit }) {
      const result = await GetCategoryOneId()
      if (result.code === 200) {
        commit('UPDATE_ONELIST', result.data)
      }
    },
    async getCategoryTwoList({ commit }, category1Id) {
      this.category2Id = undefined
      this.category3Id = undefined
      this.category3List = []
      const result = await GetCategoryTwoUrl(category1Id)
      if (result.code === 200) {
        commit('UPDATE_TWOLIST', result.data)
      }
    },
    async getCategoryThreeList({ commit }, category2Id) {
      this.category3Id = undefined
      const result = await GetCategoryThreeUrl(category2Id)
      if (result.code === 200) {
        commit('UPDATE_ThreeLIST', result.data)
      }
    }
  }
}
